<template>
  <homePanelVue title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
    <template #right>
      <xtx-more></xtx-more>
    </template>
    <template #main>
      <ul ref="pannel" class="goods-list">
        <li v-for="item in newList" :key="item.id">
          <RouterLink :to="`/goods/${item.id}`">
            <img v-lazy-img="item.picture" alt=""/>
            <p class="name" v-lazy-name="item.name">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </homePanelVue>
</template>

<script>
// 引入子组件
import homePanelVue from './home-panel.vue'
// 引入接口
import { getNew } from '@/api/home.js'
import { ref } from 'vue'
export default {
  name: 'HomeNew',
  components: {
    homePanelVue
  },
  setup () {
    // 1.定义响应式数据
    const newList = ref([])
    // 2.定义函数 函数内部调用接口函数
    async function getNewList () {
      const res = await getNew(4)
      newList.value = res
    }
    getNewList()
    return {
      newList
    }
  }
}
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
